//
//  TMWorkingTeacherController.m
//  国学商家管理
//
//  Created by Tao Li on 2018/6/20.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "TMWorkingTeacherController.h"
#import "TMWorkingTeacherCell.h"
#import "TMTeacherDetailController.h"
#import "TMNearbyViewModel.h"
#import "TMShopCourseModel.h"
@interface TMWorkingTeacherController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UICollectionView *workingTCollectionV;
@property (nonatomic, assign) CGSize itemSize;
@property (nonatomic, strong) TMNearbyViewModel *viewModel;
@property (nonatomic, strong) NSMutableArray *listArray;
@property (nonatomic, strong) WZNoResultView *noResultView;
@end

@implementation TMWorkingTeacherController
-(NSMutableArray *)listArray{
    if (!_listArray) {
        _listArray = [NSMutableArray array];
    }
    return _listArray;
}
- (void)setWorkingTCollectionV:(UICollectionView *)workingTCollectionV{
    _workingTCollectionV = workingTCollectionV;
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.minimumLineSpacing = 12.;
    flowLayout.minimumInteritemSpacing = 0.;
    _itemSize = CGSizeMake(107 * kWindowW /375, 138 * kWindowW /375);
    _workingTCollectionV.collectionViewLayout = flowLayout;
    _workingTCollectionV.scrollEnabled = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"在职教师";
    self.viewModel = [[TMNearbyViewModel alloc]init];
    self.workingTCollectionV.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        //self.cid
        [self.viewModel getWorkingTeacherWithParam:self.cid Success:^(id responseObject) {
            self.listArray = responseObject;
            [self.workingTCollectionV.mj_header endRefreshing];
            [self noResultViewShowORNot];
            [self.workingTCollectionV reloadData];
        } Failed:^(NSString *error) {
            [self.workingTCollectionV.mj_header endRefreshing];
            [self noResultViewShowORNot];
            [self.workingTCollectionV reloadData];
        }];
    }];
    [self.workingTCollectionV.mj_header beginRefreshing];
}
#pragma delegate datas

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return self.itemSize;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(14, 12, 0, 12);
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.listArray.count;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    TMWorkingTeacherCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TMWorkingTeacherCell" forIndexPath:indexPath];
    cell.model = self.listArray[indexPath.row];
//    for (UIButton *btn in cell.starsBtnCollection) {
//        if (indexPath.item%2 == 0) {
//            if (btn.tag >51) {
//                btn.hidden = YES;
//            }
//        }
//    }
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    TMTeacherDetailController *vc = [[UIStoryboard storyboardWithName:@"Nearby" bundle:nil] instantiateViewControllerWithIdentifier:@"TMTeacherDetailController"];
    vc.isTeacherDetail = YES;
    TMShopTeacherModel *mdoel = self.listArray[indexPath.row];
    vc.tid =  mdoel.htid;
    [self.navigationController pushViewController:vc animated:YES];
}
- (WZNoResultView *)noResultView{
    if (!_noResultView) {
        _noResultView = [[[NSBundle mainBundle] loadNibNamed:@"WZNoResultView" owner:nil options:nil]firstObject];
        if (kWindowH == 812.0) {
            _noResultView.frame = CGRectMake(0, 0, kWindowW, kWindowH);
        }else {
            _noResultView.frame = CGRectMake(0, 0, kWindowW, kWindowH);
        }
        _noResultView.isSearchVC = YES;
        [self.workingTCollectionV addSubview:_noResultView];
    }
    return _noResultView;
}
- (void)noResultViewShowORNot{
    if (!self.listArray.count) {
        self.noResultView.hidden = NO;
    }else{
        self.noResultView.hidden = YES;
    }
}
@end
